Skip to content

Conversation

@FrancoGiachetta
Copy link
Contributor

@FrancoGiachetta FrancoGiachetta commented Nov 18, 2025

Refactor of bounded_int_mul libfunc

Refactor of the algorithm to multiply BoundedInt and addition of tests for different cases.

We have C = A * B, where all of them are BoundedInt. We represent the a BoundedInt as:

  • X = Xo + Xd, where
    • X is a BoundedInt.
    • Xo is the lower bound of the BoundedInt range.
    • Xd is the offset.

So we want to get Cd and we have:
Co + Cd = ( Ao + Ad ) * ( Bo + Bd ) -> Cd = (Ad * Bd) + (Ad * Bo) + (Bd * Ao) + (Ao * Bo - Co)

Closes #1450

Introduces Breaking Changes?

No.

Checklist

  • Linked to Github Issue.
  • Unit tests added.
  • Integration tests added.
  • This change requires new documentation.
    • Documentation has been added/updated.

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 95.12195% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.75%. Comparing base (79da595) to head (6138f15).

Files with missing lines Patch % Lines
src/libfuncs/bounded_int.rs 95.12% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1470      +/-   ##
==========================================
+ Coverage   81.69%   81.75%   +0.06%     
==========================================
  Files         105      105              
  Lines       26047    26174     +127     
==========================================
+ Hits        21279    21399     +120     
- Misses       4768     4775       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link

Benchmark results Main vs HEAD.

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_insert.cairo (JIT) 2.530 ± 0.020 2.494 2.562 1.03 ± 0.01
base dict_insert.cairo (AOT) 2.445 ± 0.015 2.421 2.464 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_insert.cairo (JIT) 2.574 ± 0.028 2.530 2.614 1.04 ± 0.01
head dict_insert.cairo (AOT) 2.470 ± 0.015 2.439 2.493 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_snapshot.cairo (JIT) 2.244 ± 0.012 2.228 2.264 1.05 ± 0.01
base dict_snapshot.cairo (AOT) 2.142 ± 0.020 2.102 2.166 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_snapshot.cairo (JIT) 2.261 ± 0.020 2.230 2.293 1.05 ± 0.01
head dict_snapshot.cairo (AOT) 2.163 ± 0.021 2.134 2.208 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base factorial_2M.cairo (JIT) 2.603 ± 0.015 2.586 2.637 1.01 ± 0.01
base factorial_2M.cairo (AOT) 2.569 ± 0.017 2.541 2.593 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head factorial_2M.cairo (JIT) 2.641 ± 0.014 2.618 2.659 1.01 ± 0.01
head factorial_2M.cairo (AOT) 2.610 ± 0.026 2.580 2.658 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base fib_2M.cairo (JIT) 2.133 ± 0.012 2.111 2.148 1.01 ± 0.01
base fib_2M.cairo (AOT) 2.104 ± 0.012 2.085 2.119 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head fib_2M.cairo (JIT) 2.192 ± 0.022 2.155 2.230 1.03 ± 0.01
head fib_2M.cairo (AOT) 2.127 ± 0.016 2.101 2.149 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base heavy_circuit.cairo (JIT) 14.992 ± 0.026 14.951 15.035 1.03 ± 0.00
base heavy_circuit.cairo (AOT) 14.572 ± 0.051 14.505 14.679 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head heavy_circuit.cairo (JIT) 13.957 ± 0.059 13.869 14.091 1.03 ± 0.01
head heavy_circuit.cairo (AOT) 13.578 ± 0.072 13.451 13.699 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base linear_search.cairo (JIT) 2.320 ± 0.015 2.298 2.346 1.06 ± 0.01
base linear_search.cairo (AOT) 2.184 ± 0.014 2.166 2.210 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head linear_search.cairo (JIT) 2.343 ± 0.021 2.322 2.390 1.05 ± 0.01
head linear_search.cairo (AOT) 2.223 ± 0.014 2.197 2.242 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base logistic_map.cairo (JIT) 2.443 ± 0.016 2.419 2.465 1.08 ± 0.01
base logistic_map.cairo (AOT) 2.264 ± 0.009 2.250 2.281 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head logistic_map.cairo (JIT) 2.473 ± 0.014 2.454 2.494 1.08 ± 0.01
head logistic_map.cairo (AOT) 2.297 ± 0.010 2.277 2.310 1.00

@github-actions
Copy link

Benchmarking results

Benchmark for program dict_insert

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 11.022 ± 0.087 10.924 11.192 4.47 ± 0.04
cairo-native (embedded AOT) 2.468 ± 0.015 2.445 2.493 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 2.541 ± 0.017 2.522 2.574 1.03 ± 0.01

Benchmark for program dict_snapshot

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 515.7 ± 5.8 509.0 526.7 1.00
cairo-native (embedded AOT) 2157.1 ± 10.5 2140.4 2176.0 4.18 ± 0.05
cairo-native (embedded JIT using LLVM's ORC Engine) 2266.0 ± 15.5 2249.3 2295.5 4.39 ± 0.06

Benchmark for program factorial_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 4.788 ± 0.033 4.764 4.876 1.84 ± 0.01
cairo-native (embedded AOT) 2.599 ± 0.011 2.579 2.613 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 2.649 ± 0.028 2.612 2.714 1.02 ± 0.01

Benchmark for program fib_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 4.745 ± 0.034 4.702 4.831 2.23 ± 0.03
cairo-native (embedded AOT) 2.132 ± 0.025 2.097 2.179 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 2.217 ± 0.071 2.161 2.348 1.04 ± 0.04

Benchmark for program heavy_circuit

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 9.562 ± 0.067 9.447 9.674 1.00
cairo-native (embedded AOT) 14.776 ± 0.096 14.695 15.018 1.55 ± 0.01
cairo-native (embedded JIT using LLVM's ORC Engine) 15.099 ± 0.048 15.021 15.194 1.58 ± 0.01

Benchmark for program linear_search

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 551.2 ± 7.8 542.2 565.8 1.00
cairo-native (embedded AOT) 2255.9 ± 32.2 2206.2 2300.8 4.09 ± 0.08
cairo-native (embedded JIT using LLVM's ORC Engine) 2397.5 ± 53.1 2345.9 2489.9 4.35 ± 0.11

Benchmark for program logistic_map

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 371.8 ± 4.8 366.9 382.7 1.00
cairo-native (embedded AOT) 2291.0 ± 14.9 2276.9 2318.9 6.16 ± 0.09
cairo-native (embedded JIT using LLVM's ORC Engine) 2462.0 ± 8.8 2448.9 2473.8 6.62 ± 0.09

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Review bounded_int_mul libfunc

4 participants